function send(state){
  try{
    const host = location.hostname
    chrome.runtime.sendMessage({type:'video-state',state,host})
  }catch(e){}
}
function hook(v){
  if(!v.__tm){
    v.__tm=true
    v.addEventListener('play',()=>send('play'))
    v.addEventListener('pause',()=>send('pause'))
    v.addEventListener('ended',()=>send('ended'))
  }
}
function scan(){
  const vs=document.querySelectorAll('video')
  for(const v of vs) hook(v)
}
scan()
const mo=new MutationObserver(scan)
mo.observe(document.documentElement,{subtree:true,childList:true})
